package com.ddx.service.impl;

import com.ddx.common.enums.ErrorCode;
import com.ddx.common.exception.BusinessException;
import com.ddx.common.redis.RedisKey;
import com.ddx.common.redis.RedisService;
import com.ddx.service.ICommonService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author dudianbo
 * @ClassName: ${CLASSNAME}
 * @Description: ${DESCRIPTION}
 * @date 2018/4/28
 */
@Service
public class CommonServiceImpl implements ICommonService {
    private static Logger logger = LoggerFactory.getLogger(CommonServiceImpl.class);
    @Autowired
    RedisService redisService;

    /**
     * 校验手机号
     * @param mobile  手机号
     * @param type  验证码类型
     */
    @Override
    public void verifiSmsCode(String smsCode,String mobile, String type) {
        //根据手机号和发送验证码类型查询验证码
        Object a = redisService.get(RedisKey.SMS_CODE + mobile + "_" + type);
        if(a==null){
            logger.error("手机号{}找回密码接口查询redis为空",mobile);
            throw new BusinessException(ErrorCode.ESSAGE_ERROR_M407);
        }
        if(!smsCode.equals(a.toString())){
            logger.error("验证码{}{}密码接口校验失败",smsCode,a);
            throw new BusinessException(ErrorCode.ESSAGE_ERROR_M407);
        }
    }
}
